package test;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class CircluarPath extends JPanel{
	private double angle = 0;
	private int x;
	private int y;
	
	public CircluarPath()
	{
		setSize(500,500);
	}
	
	public void start() throws InterruptedException
	{
		while(true)
		{
			x = (int) (200*Math.sin(angle))+200;
			y = (int) (200*Math.cos(angle))+200;
			
			angle = angle + 0.1;
			if(angle >360)
				angle = 0;
			
			Thread.sleep(40);
			repaint();
			
			System.out.println("x = "+x+", y= "+y);
		}
	}
	
	@Override
	public void paint(Graphics g) {
		g.setColor(Color.GRAY);
		g.fillRect(0, 0,500, 500);
		
		g.setColor(Color.GREEN);
		g.fillOval(x, y, 20, 20);
		
	}
	
	public static void main(String[] args)
	{
		
		CircluarPath bb = new CircluarPath();
		JFrame jf = new JFrame();
		jf.setSize(500, 500);
		jf.add(bb);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		
		try {
			bb.start();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
